<template>
  <div>
  <avue-crud ref="crud"
    :page='page'
    :data='couponList'
    :table-loading='dataListLoading'
    :option='tableOption'
    @on-load='getCouponList'
    @refresh-change='refreshChange'>  
  <template slot-scope="" slot="menuLeft">
    <el-button type="primary" size="small" @click.stop="addOrUpdate()">新增</el-button>
  </template>

  <template slot-scope="scope" slot="menu">
    <el-button type="primary" @click.stop="addOrUpdate(scope.row)">编辑</el-button>
    <el-button type="danger" @click.stop="deleteHandle(scope.row.couponId)">删除</el-button>
  </template>

  <template slot-scope="scope" slot="couponType">
    <el-tag v-if="scope.row.couponType == 0" type="warning">无门槛</el-tag>
    <el-tag v-if="scope.row.couponType == 1" type="primary">满减</el-tag>
  </template>
  
  <template slot-scope="scope" slot="fullAmountReduce">
    <span v-if="scope.row.couponType == 0"><el-tag type="success">{{scope.row.fullAmountReduce}}</el-tag></span>
    <span v-if="scope.row.couponType == 1">
      <span> 满 <el-tag type="success">{{scope.row.reduceMoney}}</el-tag></span>
      <span> 减 <el-tag type="success">{{scope.row.fullAmountReduce}}</el-tag></span>
    </span>
    
  </template>
  </avue-crud>
  <addOrUpdate 
    v-if="addOrUpdateVisible"
    ref="addOrUpdate"
    @refreshDataList="getCouponList"></addOrUpdate>
  </div>
</template>

<script>
import {tableOption} from '../../../crud/finance/shopCoupon'
import addOrUpdate from './shopCoupon-addOrUpdate'
export default {
  data() {
    return {
      addOrUpdateVisible:false,
      tableOption: tableOption,
      couponList:[],
      dataListLoading: false,
      page:{
        total: 0,
        currentPage: 1,
        size: 10
      }
    }
  
  },

  components:{
    addOrUpdate
  },

  methods:{
    getCouponList(page,params){
      this.$http({
        url: this.$http.adornUrl('/coupon/coupon/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign({
            current: page?page.currentPage:this.page.currentPage,
            total: page?page.total:this.page.total,
            size: page?page.size: this.page.size,
            couponKind: 1
          })
        )
      }).then(({data}) =>{
        console.log(data);
        this.couponList = data.records
        this.page.total = data.total
      })
    },

    refreshChange(){

    },

    addOrUpdate(row){
      this.addOrUpdateVisible = true
      this.$nextTick(()=>{
        this.$refs.addOrUpdate.init(row)
      })
    },

    deleteHandle(id){
      this.$http({
        url: this.$http.adornUrl('/coupon/coupon'),
        method:'delete',
        data: this.$http.adornData([id], false)
      }).then(({data}) => {
        this.getCouponList()
      })
      
    }
  }
}
</script>
<style lang="">
  
</style>